package lzy.impl.smallspring.context.support;

import lzy.impl.smallspring.beans.factory.ConfigurableListableBeanFactory;
import lzy.impl.smallspring.beans.factory.support.DefaultBeanFactory;

/**
 * 定义了refreshBeanFactory的行为：新建一个新的BF并load所有的beandefinition
 * <p>
 * 但将load BeanDefinition的能力交由具体实现类实现
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() {
        DefaultBeanFactory newFactory = createFactory();
        loadBeanDefinition(newFactory);
        beanFactory = newFactory;
    }

    private DefaultBeanFactory createFactory() {
        return new DefaultBeanFactory();
    }

    protected abstract void loadBeanDefinition(DefaultBeanFactory factory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
